<?php

class category_Form_Search extends Zend_Form
{
    protected $_noDecorator = array(
        'ViewHelper', 
        'Errors'
    );	

    public function cluBuild($params)
    {
        // set the method for the display form to POST
//        $actionSearchForm = $params['view']->hvnUrl(array('module' => 'category', 'action'=>'search'), 'nocontroller');
//        $this->setAction($actionSearchForm);
//        die_a($actionSearchForm);
        $this->setAttrib('id', 'new_category');
        $this->setMethod('POST');
        $this->setAction($params['action_url']);

        $myValidator = new Zend_Validate_Regex('/^[A-Z0-9_\s\-]*$/i'); //alpha, num, space, -, _
        $myValidator->setMessage(__("Only alphanum, spaces, -, _ allowed"), Zend_Validate_Regex::NOT_MATCH);
        $this->addElementPrefixPath('Clu_Filter', 'Clu/Filter/', 'filter');
                
		//add name
		$name = new Zend_Form_Element_Text('name', 
                         array('disableLoadDefaultDecorators' => true,
//                               'required'   => true,             
                               'class' => 'inputText'));
        $name->addDecorators($this->_noDecorator)
        	 ->addValidator($myValidator);
        $this->addElement($name);
        
        //add pid
        $pid = new Zend_Form_Element_Select('pid', 
                         array('disableLoadDefaultDecorators' => true,
                               'required'   => true));
        $pid->addMultiOption('0',__('Root'));                 
    	$mCategory = new category_Model_Category();
    	$mCategory->setTables($params['type']);
    	$tmp = $mCategory->getTree(0);
        foreach ($tmp as $c) {
            $pid->addMultiOption($c['id'], $c['displayName']);
        }
        $pid->addDecorators($this->_noDecorator);
        $this->addElement($pid);
		
        // add the submit button
        $submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true, 
                                                               'label' => __('Search') ));
        $submit->addDecorators($this->_noDecorator);
        $this->addElement($submit);
    }
} 
?>